/*
 * @Date: 2025-02-27 10:28:34
 * @Auth: 873768511@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-09-22 17:44:49
 * @FilePath: \corpus\src\pages\catalogue\list\hooks\index.ts
 */
import type { ActionType, FormInstance } from '@ant-design/pro-components';
import { useRequest } from 'ahooks';
import { Form } from 'antd';
import { createContainer } from 'unstated-next';
// import {

// } from '@/services/rulesCenter/modelManagement/list';
import { getCatalog } from '@/services/ant-design-pro/resource';
import { useModel } from '@umijs/max';
import { useRef, useState } from 'react';
export default createContainer(() => {
  // 查询列表form
  const [form] = Form.useForm();
  const tableRef = useRef<ActionType>();
  const formRef = useRef<FormInstance>();

  const { actionRef, selectedKeys } = useModel('useTree', (model) => {
    return {
      selectedKeys: model.selectedKeys,
      actionRef: model.actionRef,
    };
  });
  // 删除
  const [total, setTotal] = useState(0);
  const getTableList = useRequest(
    async ({ ...query }) => {
      console.log(selectedKeys);
      console.log(query);
      const res = await getCatalog({
        ...query,
        sourceOrgCode: selectedKeys.toString(),
      });
      setTotal(res?.total || 0);
      return {
        data: res?.data || [],
        total: res?.total || 0,
        success: res?.success,
      };
    },
    {
      manual: true,
    },
  );
  return {
    form,
    tableRef,
    formRef,
    getTableList,
    total,
  };
});
